using MicroMsg.Common.Event;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class SnsPostVisiItem : UserControl
	{
		private const string TAG = "SnsPostVisiItem";
		public static DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(SnsPostVisiItem), new PropertyMetadata(false, new PropertyChangedCallback(SnsPostVisiItem.OnIsCheckedPropertyChanged)));
		public static DependencyProperty mItemKindProperty = DependencyProperty.Register("mItemKind", typeof(SnsPostVisiItemKind), typeof(SnsPostVisiItem), new PropertyMetadata(SnsPostVisiItemKind.Kind_CustomGroup, new PropertyChangedCallback(SnsPostVisiItem.OnmItemKindPropertyChanged)));
		public static DependencyProperty mSnsGroupProperty = DependencyProperty.Register("mSnsGroup", typeof(SnsTagInfo), typeof(SnsPostVisiItem), new PropertyMetadata(null, new PropertyChangedCallback(SnsPostVisiItem.OnmSnsGroupPropertyChanged)));
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		internal Button btnLayoutRoot;
		internal Image imgCheckBoxTag;
		internal TextBlock txtTitle;
		internal TextBlock txtMemberCnt;
		internal TextBlock txtDescription;
		private bool _contentLoaded;
		public event MMStandardUIEvent CheckStageChanged;
		public bool IsChecked
		{
			get
			{
				return (bool)base.GetValue(SnsPostVisiItem.IsCheckedProperty);
			}
			set
			{
				base.SetValue(SnsPostVisiItem.IsCheckedProperty, value);
			}
		}
		public SnsPostVisiItemKind mItemKind
		{
			get
			{
				return (SnsPostVisiItemKind)base.GetValue(SnsPostVisiItem.mItemKindProperty);
			}
			set
			{
				base.SetValue(SnsPostVisiItem.mItemKindProperty, value);
			}
		}
		public SnsTagInfo mSnsGroup
		{
			get
			{
				return (SnsTagInfo)base.GetValue(SnsPostVisiItem.mSnsGroupProperty);
			}
			set
			{
				base.SetValue(SnsPostVisiItem.mSnsGroupProperty, value);
			}
		}
		public SnsPostVisiItem()
		{
			this.InitializeComponent();
			this.refreshCheckedStage();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private static void OnIsCheckedPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SnsPostVisiItem.IsCheckedProperty)
			{
				(dependencyObject_0 as SnsPostVisiItem).IsCheckedPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void IsCheckedPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.refreshCheckedStage();
			}
		}
		private static void OnmItemKindPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SnsPostVisiItem.mItemKindProperty)
			{
				(dependencyObject_0 as SnsPostVisiItem).mItemKindPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void mItemKindPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.refreshCheckedStage();
			}
		}
		private static void OnmSnsGroupPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SnsPostVisiItem.mSnsGroupProperty)
			{
				(dependencyObject_0 as SnsPostVisiItem).mSnsGroupPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void mSnsGroupPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.RefreshItem();
			}
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.mItemKind == SnsPostVisiItemKind.Kind_GeneralSet && this.IsChecked)
			{
				return;
			}
			this.IsChecked = !this.IsChecked;
			if (this.CheckStageChanged != null)
			{
				this.CheckStageChanged(this, this.IsChecked);
			}
		}
		private void RefreshItem()
		{
			if (this.mItemKind != SnsPostVisiItemKind.Kind_CustomGroup)
			{
				return;
			}
			if (this.mSnsGroup == null)
			{
				this.txtTitle.set_Text("");
				this.txtMemberCnt.set_Text("");
				return;
			}
			this.txtTitle.set_Text(this.mSnsGroup.strTagName);
			this.txtMemberCnt.set_Text("(" + this.mSnsGroup.nCount + ")");
		}
		private void refreshCheckedStage()
		{
			if (this.IsChecked)
			{
				if (this.mItemKind == SnsPostVisiItemKind.Kind_CustomGroup)
				{
					this.imgCheckBoxTag.set_Source(ToolFunction.GetImgFromContentSource(R.theme.SnsGroup_Check));
					return;
				}
				this.imgCheckBoxTag.set_Source(ToolFunction.GetImgFromContentSource(R.theme.SnsCustG_check));
				return;
			}
			else
			{
				if (this.mItemKind == SnsPostVisiItemKind.Kind_CustomGroup)
				{
					this.imgCheckBoxTag.set_Source(ToolFunction.GetImgFromContentSource(R.theme.SnsGroup_UnCheck));
					return;
				}
				this.imgCheckBoxTag.set_Source(ToolFunction.GetImgFromContentSource(R.theme.SnsCustG_Uncheck));
				return;
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/UploadAndPost/SnsPostVisiItem.xaml", 2));
			this.btnLayoutRoot = (Button)base.FindName("btnLayoutRoot");
			this.imgCheckBoxTag = (Image)base.FindName("imgCheckBoxTag");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.txtMemberCnt = (TextBlock)base.FindName("txtMemberCnt");
			this.txtDescription = (TextBlock)base.FindName("txtDescription");
		}
	}
}
